package com.luping.xiao.xiao.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luping.xiao.xiao.dao.SysUserDao;
import com.luping.xiao.xiao.domain.SysUser;
import com.luping.xiao.xiao.service.SysUserService;
import com.luping.xiao.xiao.utils.Thread.ThreadQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserImpl extends ServiceImpl<SysUserDao, SysUser> implements SysUserService {
    protected static final Logger log = LoggerFactory.getLogger(SysUserImpl.class);

    @Autowired
    private SysUserDao sysUserDao;

    @Override
    public void insertList(List<SysUser> list) {
       log.info("listSize=" + list.size());
        insertBa(list);
    }

    public void insertBa(List<SysUser> list) {
        int insertLength = list.size();
        int i = 0;
        while (insertLength > 1000) {
            saveBatchSysUser(list.subList(i, i + 1000));
            i = i + 1000;
            insertLength = insertLength - 1000;
        }
        if (insertLength > 0) {
            saveBatchSysUser(list.subList(i, i + insertLength));
        }
//        log.info("insertBa");
    }

    public void saveBatchSysUser(List<SysUser> list){
        ThreadQueue.currentTaskStat = ThreadQueue.EXTRACTOR_STAT.STORE_RUNNING;
        sysUserDao.saveBatch(list);
    }
}
